const cart=require("../database/cart")

module.exports=async (req,res)=>{
  const {num,proID,price,img,brief1}=req.body
  console.log(req.body);
  const cardData=await cart.find({proID})
  if(cardData.length<1){
    await cart.insertMany({
      proID,price,img,brief1,num
    })
    const data=await cart.find({})
    res.send(data)
  }else{
    let data2=await cart.find({proID})
    console.log(data2,proID);
    const num1=data2.length?data2[0].num:0
    await cart.updateOne({proID},{num:num1+num*1})
    const data=await cart.find({})
    res.send(data)
  }
}